package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anotion.AutoId;
import com.sky.dto.common.QueryParams;
import com.sky.entity.Dict;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DictMapper {
    /**
     * 获取字典数据 - 分类下的对应数据
     * @param params
     * @return
     */
    Page<Dict> getDicData(QueryParams params);

    @AutoId
    void addDicData(Dict dict);

    void updateDicData(Dict dict);

    @Delete("DELETE FROM dict WHERE id = #{id}")
    void deleteDicData(String id);

    Page<Dict> getDicDataAll(QueryParams params);


    /**
     * 根据父id查找父节点的字典数量
     * @param id
     * @return
     */
    @Select("SELECT COUNT(*) FROM dict WHERE pid = #{id}")
    int countByPid(String id);
    @Select("SELECT * FROM dict WHERE dict_code = #{dictCode} AND pid IS NOT NULL AND pid != ''")
    List<Dict> getDicDataTree(String dictCode);

   /**
    * 获取分类字典下的 一级分类的总数量
    */
    @Select("SELECT COUNT(*) FROM dict WHERE pid = #{id}")
    Long getTopLevelDictCount(String id);

    /**
     * 根据父 pid 查找数据 --
     * @param parentId
     * @return 返回list 集合
     */
    @Select("SELECT * FROM dict WHERE pid = #{parentId}")
    List<Dict> getDicDataTreeById(String parentId);
}
